<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>pthread_mutexattr_settype</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_1558">&nbsp;</a>NAME</h4><blockquote>
pthread_mutexattr_gettype, pthread_mutexattr_settype
- get or set a mutex type
</blockquote><h4><a name = "tag_000_007_1559">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="pthread.h.html">pthread.h</a>&gt;

int pthread_mutexattr_gettype(const pthread_mutexattr_t <i>*attr</i>, int <i>*type</i>);
int pthread_mutexattr_settype(pthread_mutexattr_t <i>*attr</i>, int <i>type</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_1560">&nbsp;</a>DESCRIPTION</h4><blockquote>
The 
<i>pthread_mutexattr_gettype()</i>
and 
<i>pthread_mutexattr_settype()</i>
functions respectively get and set the mutex <i>type</i> attribute.
This attribute is set in the <i>type</i> parameter
to these functions. The default value of the <i>type</i>
attribute is PTHREAD_MUTEX_DEFAULT.
<p>
The type of mutex is contained in the <i>type</i> attribute of the
mutex attributes. Valid mutex types include:
<dl compact>

<dt>PTHREAD_MUTEX_NORMAL<dd>

This type of mutex does not detect deadlock. A thread
attempting to relock this mutex without first unlocking it
will deadlock.  Attempting to unlock a
mutex locked by a different thread results in undefined behaviour.
Attempting to unlock an unlocked
mutex results in undefined behaviour.

<dt>PTHREAD_MUTEX_ERRORCHECK<dd>

This type of mutex provides error checking.  A thread
attempting to relock this mutex without first unlocking it
will return with an error.
A thread attempting to unlock a mutex which another
thread has locked will return with an error.
A thread attempting to unlock an unlocked mutex will
return with an error. 

<dt>PTHREAD_MUTEX_RECURSIVE<dd>

A thread attempting to relock this mutex without first
unlocking it will succeed in locking the mutex. The relocking
deadlock which can occur with
mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type
of mutex. Multiple
locks of this mutex require the same number of unlocks to release
the mutex before another thread
can acquire the mutex.
A thread attempting to unlock a mutex which another thread has
locked will return with an error. A thread attempting to 
unlock an unlocked mutex will return with an error.

<dt>PTHREAD_MUTEX_DEFAULT<dd>

Attempting to recursively lock a mutex of this type results in
undefined behaviour. Attempting to unlock a mutex of this type which
was not locked by the calling
thread results in undefined behaviour. Attempting to unlock a mutex
of this type which is not locked results in undefined behaviour. 
An implementation is allowed to map this mutex to one of the
other mutex types.

</dl>
</blockquote><h4><a name = "tag_000_007_1561">&nbsp;</a>RETURN VALUE</h4><blockquote>
If successful, the 
<i>pthread_mutexattr_settype()</i>
function 
returns zero.  Otherwise, an error number is
returned to indicate the error.
<p>
Upon successful completion, the 
<i>pthread_mutexattr_gettype()</i>
function returns zero and stores the value of the
<i>type</i> attribute of <i>attr</i> into the object referenced by the
<i>type</i>
parameter.  Otherwise an error is returned to indicate
the error.
<br>
</blockquote><h4><a name = "tag_000_007_1562">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>pthread_mutexattr_gettype()</i>
and 
<i>pthread_mutexattr_settype()</i>
functions will fail if:
<dl compact>

<dt>[EINVAL]<dd>
The value <i>type</i> is invalid.

</dl>
<p>
The
<i>pthread_mutexattr_gettype()</i>
and
<i>pthread_mutexattr_settype()</i>
functions may fail if:
<dl compact>

<dt>[EINVAL]<dd>The value specified by <i>attr</i> is invalid.

</dl>
</blockquote><h4><a name = "tag_000_007_1563">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1564">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
It is advised that an application should not use
a PTHREAD_MUTEX_RECURSIVE mutex with condition variables
because the implicit unlock performed for a 
<i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>
or 
<i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>
may not actually release the
mutex (if it had been locked multiple times). If this happens,
no other thread can satisfy the condition of the predicate.
</blockquote><h4><a name = "tag_000_007_1565">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_1566">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i>,
<i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i>,
<i><a href="pthread.h.html">&lt;pthread.h&gt;</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
